package cn.nange.cmfz.service.impl;

import cn.nange.cmfz.dao.ArticleDao;
import cn.nange.cmfz.entity.Article;
import cn.nange.cmfz.service.ArticleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleDao articleDao;

    @Override
    public void add(Article a) {
        articleDao.insert(a);
    }

    @Override
    public void update(Article a) {
        articleDao.update(a);
    }

    @Override
    public void delete(Integer id) {
        articleDao.delete(id);
    }

    @Override
    public Article showOne(Integer id) {
        return articleDao.selectOne(id);
    }

    @Override
    public PageInfo<Article> showAll(int page, int rows) {
        PageHelper.startPage(page, rows);
        PageInfo<Article> pageInfo = new PageInfo<>(articleDao.selectAll());
        return pageInfo;
    }
}
